package org.misty.practices.gc;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author Misty on 2020-06-08
 */
public class HashCodeTest {
    public static Data fillMem() {
        List<Data> list = new ArrayList<>(1024);
        Data last = null;
        try {
            for (int i = 1; i <= 30000; i++) {
                list.add(last = new Data());
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println(System.identityHashCode(last));
        return last;
    }

    public static void main(String[] args) throws InterruptedException {
        Data d = fillMem();
        System.gc();
        TimeUnit.SECONDS.sleep(2);
        System.out.println(System.identityHashCode(d));
    }

    static class Data {
        private byte[] arr = new byte[1024];
    }
}
